using System.Runtime.CompilerServices;

namespace MauiBuilder.Services
{
    /// <summary>
    /// 设置管理器，用于保存和加载应用设置
    /// </summary>
    public class SettingsManager
    {
        private static SettingsManager _instance;
        public static SettingsManager Instance => _instance ??= new SettingsManager();

        private SettingsManager()
        {
        }

        /// <summary>
        /// 保存布尔值设置
        /// </summary>
        /// <param name="key">设置键</param>
        /// <param name="value">设置值</param>
        public void SaveSetting(string key, bool value)
        {
            Preferences.Default.Set(key, value);
        }

        /// <summary>
        /// 保存字符串设置
        /// </summary>
        /// <param name="key">设置键</param>
        /// <param name="value">设置值</param>
        public void SaveSetting(string key, string value)
        {
            Preferences.Default.Set(key, value);
        }

        /// <summary>
        /// 保存整数设置
        /// </summary>
        /// <param name="key">设置键</param>
        /// <param name="value">设置值</param>
        public void SaveSetting(string key, int value)
        {
            Preferences.Default.Set(key, value);
        }

        /// <summary>
        /// 加载布尔值设置
        /// </summary>
        /// <param name="key">设置键</param>
        /// <param name="defaultValue">默认值</param>
        /// <returns>设置值</returns>
        public bool LoadSetting(string key, bool defaultValue)
        {
            return Preferences.Default.Get(key, defaultValue);
        }

        /// <summary>
        /// 加载字符串设置
        /// </summary>
        /// <param name="key">设置键</param>
        /// <param name="defaultValue">默认值</param>
        /// <returns>设置值</returns>
        public string LoadSetting(string key, string defaultValue)
        {
            return Preferences.Default.Get(key, defaultValue);
        }

        /// <summary>
        /// 加载整数设置
        /// </summary>
        /// <param name="key">设置键</param>
        /// <param name="defaultValue">默认值</param>
        /// <returns>设置值</returns>
        public int LoadSetting(string key, int defaultValue)
        {
            return Preferences.Default.Get(key, defaultValue);
        }

        #region 应用设置键常量

        /// <summary>
        /// 深色模式设置键
        /// </summary>
        public const string DarkModeKey = "DarkModeEnabled";

        /// <summary>
        /// 通知启用设置键
        /// </summary>
        public const string NotificationsEnabledKey = "NotificationsEnabled";

        /// <summary>
        /// 声音启用设置键
        /// </summary>
        public const string SoundEnabledKey = "SoundEnabled";

        /// <summary>
        /// 震动启用设置键
        /// </summary>
        public const string VibrationEnabledKey = "VibrationEnabled";

        /// <summary>
        /// 通知间隔设置键
        /// </summary>
        public const string NotificationIntervalKey = "NotificationInterval";

        /// <summary>
        /// 选择语言设置键
        /// </summary>
        public const string SelectedLanguageKey = "SelectedLanguage";

        #endregion
    }
}